package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.aistar.pojo.UserAddress;
import tech.aistar.service.UserAddressService;
import java.util.List;

@RestController
@RequestMapping("/useraddress")
@CrossOrigin(origins = "http://localhost:5173")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    /**
     * 根据用户ID获取地址列表
     * @param userId 用户ID
     * @return 地址列表
     */
    @GetMapping("/list")
    public List<UserAddress> list(@RequestParam Integer userId) {
        System.out.println("=== 接收到地址列表请求 ===");
        System.out.println("请求的userId: " + userId);

        List<UserAddress> addresses = userAddressService.findByUserId(userId);

        System.out.println("查询到的地址数量: " + addresses.size());
        addresses.forEach(addr -> {
            System.out.println("地址信息: " + addr);
        });

        return addresses;
    }
}